import { useRef, useEffect } from "react";
import Child from "./Child";

function App() {
  const childRef = useRef(null);
  const h1Ref = useRef(null);

  useEffect(() => {
    console.log(h1Ref.current);
    console.log(childRef.current);
  }, []);

  return (
    <>
      {/* 给DOM元素绑定ref，可以获取真实DOM元素 */}
      <h1 ref={h1Ref}>App</h1>
      {/* 给组件绑定ref，默认啥也得不到 */}
      {/* 子组件需要使用forwardRef才能被父组件获取DOM元素 */}
      <Child ref={childRef} />
    </>
  );
}

export default App;
